package com.jxc.jxcmanage.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jxc.jxcmanage.common.ResultBean;
import com.jxc.jxcmanage.dto.ProductInventoryDto;
import com.jxc.jxcmanage.service.ProductInventoryService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/productInventory")
public class ProductInventoryController {
	

	@Autowired
	private ProductInventoryService productInventoryService;

	/**
	 * 产品分页
	 * 
	 * @param param
	 * @return
	 */
	@PostMapping("/page")
	public ResultBean page(@RequestBody ProductInventoryDto param) {
		return productInventoryService.page(param);

	}


	/**
	 * 产品保存
	 * 
	 * @param param
	 * @return
	 */
	@PostMapping("/save")
	public ResultBean save(@RequestBody ProductInventoryDto param) {
		return productInventoryService.save(param);

	}

	/**
	 * 保存或更新
	 * @param param
	 * @return
	 */
	@PostMapping("/addOrUpdateInfo")
	public ResultBean addOrUpdateInfo(@RequestBody ProductInventoryDto param) {
		return productInventoryService.addOrUpdateInfo(param);

	}

	/**
	 * 产品更新
	 * 
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResultBean update(@RequestBody ProductInventoryDto param) {
		return productInventoryService.update(param);
	}

	/**
	 * 产品删除
	 * 
	 * @param param
	 * @return
	 */
	@PostMapping("/delete")
	public ResultBean delete(@RequestBody ProductInventoryDto param) {
		return productInventoryService.delete(param);
	}

	/**
	 * 产品库存导出
	 *
	 * @return
	 */
//	@PostMapping("/exportCsv")
//	public ResultBean export(@RequestBody ProductInventoryDto param) {
//		return productInventoryService.exportCsv(param);
//	}
    @RequestMapping("/exportCsv")
    public ResultBean export(HttpServletRequest request, HttpServletResponse response) {
        ProductInventoryDto param = new ProductInventoryDto();
        String productId = request.getParameter("productId");
        String supplierId = request.getParameter("supplierId");
        if(!StringUtils.isEmpty(productId)){
            param.setProductId(Long.valueOf(productId));
        }
        if(!StringUtils.isEmpty(supplierId)){
            param.setSupplierId(Long.valueOf(supplierId));
        }
        return productInventoryService.exportCsv(param);
    }
}
